const App = getApp();

// 验证类
import Verify from '../../utils/verify.js';
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		title: '',
		content: '',
		image: ['/images/icon/morentupain.png'],
		imageid:[]
	},

	bindsubmit() {
		let _this = this;
		if (_this.data.image.length < 5) {
			_this.data.image.pop()
		}
		if (!_this.data.title) {
			App.showError('标题不能为空');
			return false;
		}
		if (!_this.data.content) {
			App.showError('内容不能为空');
			return false;
		}
		if (!_this.data.image) {
			App.showError('图片不能为空');
			return false;
		}
		App._post_form('feedback/add', {title:_this.data.title,content:_this.data.content,image:_this.data.imageid}, result => {
			wx.switchTab({
				url:"/pages/user/index"
			})
		});
	},

	loadImg: function() {
		var that = this;
		wx.chooseImage({
			count: 1,
			sizeType: ['original', 'compressed'],
			sourceType: ['album', 'camera'],
			success: function(res) {
				var tempFilePaths = res.tempFilePaths;
				App._uplodeimg(tempFilePaths[0], 'upload/image', result => {
					let res = JSON.parse(result.data)
					let imgs = that.data.image;
					
					that.data.imageid.push(res.data.file_id)
					console.log(that.data.imageid)
					if (imgs.length == 1) {
						imgs.unshift(res.data.file_path)
					} else {
						imgs.pop()
						imgs.push(res.data.file_path)
						imgs.push('/images/icon/morentupain.png')
					}
					if (imgs.length == 6) {
						imgs.pop()
					}
					that.setData({
						image: imgs,
						imageid:that.data.imageid
					});
				})
			}
		})

	},

	bindinput(e) {
		this.setData({
			title: e.detail.value
		})
	},
	bindtextarea(e) {
		this.setData({
			content: e.detail.value
		})
	},


	/**
	 * 输入绑定
	 */
	onInput(e) {
		let key = e.currentTarget.dataset.key;
		this.setData({
			['queryString.' + key]: e.detail
		});
		console.log(this.data.queryString);
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {

	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {

	}
})
